<template>
  <transition
    :css="false"
    v-on:enter="enter"
    v-on:leave="leave"
  >
    <div class="miniPlay" v-show="this.isShowminiplay">
      <div class="playerwrapper" >
        <div class="player-left" @click="selectMusic">
          <img :src="currentSongs.picUrl" ref="cd">
          <div class="title">
            <h3>{{currentSongs.name}}</h3>
            <p >{{currentSongs.singer}}</p>
          </div>
        </div>
        <div class="player-right">
          <div class="play" @click="play" ref="play"></div>
          <div class="list" @click.stop="showList"></div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
import { mapActions, mapGetters } from 'vuex'
import Velocity from 'velocity-animate'
import 'velocity-animate/velocity.ui'
export default {
  name: 'MiniPlay',
  methods: {
    showList () {
      this.isshowList(!this.isShowList)
    },
    ...mapActions([
      'setFullScreen',
      'setminiplay',
      'setplay',
      'isshowList'
    ]
    ),
    selectMusic () {
      this.setFullScreen(true)
      this.setminiplay(false)
    },
    enter (el, done) {
      Velocity(el, 'transition.bounceUpIn', { duration: 500 }, function () {
        done()
      })
    },
    leave (el, done) {
      Velocity(el, 'transition.expandOut', { duration: 500 }, function () {
        done()
      })
    },
    play () {
      this.setplay(!this.isPlay)
    }
  },

  computed: {
    ...mapGetters([
      'isShowminiplay',
      'isPlay',
      'sShowList',
      'currentSongs'

    ]
    )
  },
  watch: {
    isPlay (newValue, oldValue) {
      if (newValue) {
        this.$refs.play.classList.add('active')
        this.$refs.cd.classList.add('active')
      } else {
        this.$refs.play.classList.remove('active')
        this.$refs.cd.classList.remove('active')
      }
    }
  }

}
</script>

<style scoped lang="scss">
  @import "../../assets/css/variable";
  @import "../../assets/css/mixin";
  .miniPlay{
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 150px;
    .playerwrapper{
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: space-between;
      @include bg_color();
      .player-left{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-left: 30px;
        img{
          width: 120px;
          height: 120px;
          border-radius: 50%;
          animation: sport 3s linear infinite;
          animation-play-state: paused;
          &.active{
            animation-play-state: running;
          }
        }
        .title{
          margin-left: 20px;
          h3{
            @include font_size($font_medium);
            @include font_color();
          }
          p{
            @include font_size($font_medium);
            @include font_color();
          }
        }

      }
      .player-right{
        display: flex;
        align-items: center;
        .play{
          width: 84px;
          height: 84px;

          @include bg_img('../../assets/images/play');
          &.active{
            @include bg_img('../../assets/images/pause')
          }
        }
        .list{
          width: 120px;
          height: 120px;
          @include bg_img('../../assets/images/list')
        }
      }
    }
  }
  @keyframes sport {
    from {
      transform: rotate(0deg);
    }
    to {
      transform: rotate(360deg);
    }
  }
</style>
